﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using TKB.Types.Attributes;
using TKB.Types.DataSets;
using TKB.DataService;
using System.Data;
using System.Data.SqlClient;
using TKB.Services.Tools;

namespace TKB.Services.BusinessObjects
{
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    [DefaultDatabase("TKBIthalatDB")]
    public class AnalizBS : BusinessBase
    {
        public void Save(ANALIZDataSet ds)
        {
            ITKBDataObject dto = GetTKBDataObject();
            dto.Update(ds.ANALIZ);
        }

        public DataTable SelectByMuayeneKey(Guid pMuayeneKey)
        {
            ITKBDataObject dto = GetTKBDataObject();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = @"SELECT 
                                    A.*
                                    , TA.AnalizMetodAdi
                                FROM TKBIthalatDB.dbo.ANALIZ AS A
                                    INNER JOIN TKBIthalatDB.dbo.TT_ANALIZ_METODU AS TA ON A.AnalizMetodTipNo = TA.AnalizMetodTipNo
                                WHERE A.MuayeneKey = @MuayeneKey
                                ORDER BY Adi";
            cmd.Parameters.Add(ParameterBuilder.CreateSqlParameter("@MuayeneKey", SqlDbType.UniqueIdentifier, pMuayeneKey));
            DataTable dt = new DataTable();
            dto.GetRecords(dt, cmd);
            return dt;
        }

        public ANALIZDataSet SelectDataSetByMuayeneKey(Guid pMuayeneKey)
        {
            ITKBDataObject dto = GetTKBDataObject();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = @"SELECT 
                                    A.*
                                FROM TKBIthalatDB.dbo.ANALIZ AS A
                                WHERE A.MuayeneKey = @MuayeneKey
                                ORDER BY Adi";
            cmd.Parameters.Add(ParameterBuilder.CreateSqlParameter("@MuayeneKey", SqlDbType.UniqueIdentifier, pMuayeneKey));
            ANALIZDataSet ds = new ANALIZDataSet();
            dto.GetRecords(ds.ANALIZ, cmd);
            return ds;
        }
    }
}
